package com.smfx.yxt;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeMap;

import org.apache.commons.lang.StringUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.smfx.yxt.utils.JsonUtils;
import com.smfx.yxt.wechat.model.WechatSnsToken;

public class mainService {

	public static void main(String[] args) {
		//writeAccess();
		///readAccess();
		//System.out.println(MD5Util.md5("cly123"));
		//getOpencode();
		int i = 5;
		do {
			System.out.println("my name--"+i);
			i--;
		} while (i > 1);
	}
	
	public static void getOpencode() {
		String text = "{\"access_token\":\"28_qmN_3A_LRGamA3J4ghbEhacko39a8e869qpNuuMx3ze58zMGzqpSe-rmNHWqnPK4YEstTK4WOr7h_fuAck77TBUAMtSjfcQtYZW6keLcP3I\",\"expires_in\":7200,\"refresh_token\":\"28_zAvBBUiV_03AUuxplUIVd3Cux1qvTgmpHto7JPYLXHTd8L7SwSK-qbe599ynET2wbRukBE0T2Qz64WA16mb-RsSXfexVylH23s_OQTbYsWg\",\"openid\":\"oi9nfwvRiKAMdtT7WtguxRgCv3II\",\"scope\":\"snsapi_userinfo\"}";
		try {
			JSONObject jsonObject = JSONObject.parseObject(text);
			if(StringUtils.isNotBlank(jsonObject.getString("errcode"))) {
				System.out.println("error");
			}
			WechatSnsToken result = JsonUtils.jsonToObject(jsonObject.toString(), WechatSnsToken.class);
			System.out.println(JSON.toJSONString(result));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void writeAccess() {
		try {
			File file = new File("F:\\yxtfile\\access.txt");
			if(!file.exists()) {
				file.createNewFile();
			}
			FileWriter out = new FileWriter(file);
			BufferedWriter bw= new BufferedWriter(out); 
            bw.write("access_token:dsfsdfsdf_jfdisfklsdfksidjf123333333333333231df|132423546");
            bw.write("jsapi_ticket:fsdfdsfsdfdsfjd|2435467");
            bw.newLine();
			bw.flush();
			bw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void readAccess() {
		try {
			File file = new File("F:\\yxtfile\\access.txt");
			InputStreamReader reader = new InputStreamReader(new FileInputStream(file));
            BufferedReader br = new BufferedReader(reader);
            String s = null;
            while((s=br.readLine())!=null){
                System.out.println(s);
            }
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

class xbComparator implements Comparator
{
    public int compare(Object o1,Object o2)
    {
        String i1= getStrInt(String.valueOf(o1));
        String i2=getStrInt(String.valueOf(o2));
        return -i1.compareTo(i2);
    }
    
    private static String getStrInt(String k) {
		if(k.equals("周一")) return "a";
		if(k.equals("周二")) return "b";
		if(k.equals("周三")) return "c";
		if(k.equals("周四")) return "d";
		if(k.equals("周五")) return "e";
		return "0";
	}
}
